﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Configuration;
using System.Web.UI.HtmlControls;

namespace Skywave.Web.UI
{
    public class Basic
    {
        protected HttpContext _Context;
        private System.Web.UI.Page _Page;

        public string Path_File { get; private set; }
        public string Path_Full { get; private set; }
        public string Path_FullRelative { get; private set; }

        public Basic(System.Web.UI.Page page1)
            : this(page1, null)
        { }
        public Basic(System.Web.UI.Page page1, HttpContext context)
        {
            string str1;

            if (context == null)
                _Context = System.Web.HttpContext.Current;
            else
                _Context = context;
            _Page = page1;

            Path_File = _Context.Request.AppRelativeCurrentExecutionFilePath.ToLower();
            if (!Path_File.EndsWith(".aspx"))
                Path_File += ".aspx";
            str1 = _Context.Request.QueryString.ToString().ToLower();
            Path_Full = Path_File + ((str1 == "") ? "" : "?" + str1);
            Path_FullRelative = _Context.Request.Path.ToLower() + ((str1 == "") ? "" : "?" + str1);
        }

        /// <summary>
        /// Path_CurrentTheme Property
        /// </summary>
        public string Path_CurrentTheme
        {
            get
            {
                PagesSection pageSection = System.Configuration.ConfigurationManager.GetSection("system.web/pages") as PagesSection;

                //t pageSection contains property Theme with value - the name of the current Theme
                string currentTheme = pageSection.Theme;

                //t now we could get the current theme folder physical path
                string themeDirPath = "~/App_Themes/" + pageSection.Theme + "/";
                //string themeDirPhysicalPath = HttpContext.Current.Server.MapPath(themeDirPath);

                //
                return themeDirPath;
            }
        }

        public static void Log_WriteEntry(string source, string message, EventLogEntryType logType)
        {
            // Create the source, if it does not already exist.
            if (!EventLog.SourceExists(source))
            {
                // An event log source should not be created and immediately used.
                // There is a latency time to enable the source, it should be created
                // prior to executing the application that uses the source.
                // Execute this sample a second time to use the new source.
                EventLog.CreateEventSource(source, null);
            }

            // Write an informational entry to the event log.    
            EventLog.WriteEntry(source, message, logType);
        }
    }
}
